import requests
import json


headers = {
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "no-cache",
    "content-type": "application/json;charset=UTF-8",
    "origin": "https://www.xiaohongshu.com",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://www.xiaohongshu.com/",
    "sec-ch-ua": "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Microsoft Edge\";v=\"138\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0",
    # "x-b3-traceid": "ebb9c1664ec2fb01",
    "x-mns": "unload",
    "x-s": "XYW_eyJzaWduU3ZuIjoiNTYiLCJzaWduVHlwZSI6IngyIiwiYXBwSWQiOiJ4aHMtcGMtd2ViIiwic2lnblZlcnNpb24iOiIxIiwicGF5bG9hZCI6IjVhZjY3MmQ2OWY4NWVlYjRmZWNmNmVhYzU1ZjQzODllNjI5MjM0M2QxNzZiN2FmODZjMDJkMWVlYzQ5MWJkNzEzYmNhNzE1OTFiZDdhZmJhZDM2NmY3M2FhNGZjODcyY2E1NjljMDA5M2FkMDllYjk4MWJjOTVjNGU0Mjg0YWE1NjEzNGYxZWU4NzA2MDEwZGQxODliMmE3YWY4NTY3MzU5ODcyNDU0NWRmMTEzNmU0Y2NiZTMwZTJkZWRiNDg2NmI1OTVjN2VjNTZmN2ZjMDY1ODA4ZjIzMWE5YWUxMjQwNjgwMzM0ZGQxZWQyOWYyYTkzODliM2UwYzEzYzVjMTA4OGM4YTM0MzJjZThiYmJkYmRmYzkwODYyMjI5NWMwM2UwYTdmMDMwMjgyN2RiY2IxYWM3NGQyZTUwNGUzZGEyZDVmNjA4M2FiODA3NWQ5ZDI3MmM2OG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4ebQyLEAPgb7+LSiN7+8qgz/z7b72nMl4FzQ4DS3aL+I4rRx/pPFJ04AnpmFpDSkLdkQye+ApMm7a94Q2dQ0JDEAnppT4LSkyrlo4gzCqdpFJrS94fLAqgzp/7mN8pzT4d+k/nMPanSmq7W7/7+L4gzEGMm7qLSePBpfpdzpanDM8pzA4pmQcFTAzBLMqAmc498Q4DESPMmFJpbY4gzQy7kFa/+d8pzYafpLpaRSPr8DqFzl494QzaV6a/+g/pkl4obQc7ZEanV98gY0y9SEcDESpop7wrS3LeYj4g4VHjIj2eDjwjFlweZFw/LEP/HVHdWlPsHCPsIj2erlH0ijJfRUJnbVHdF=",
    "x-t": "1751515488317",
    # "x-xray-traceid": "cbe73ab01d54d9c5ddb2cd5f005d3832"
}
cookies = {
    "abRequestId": "430c8431-b6e2-528e-9c89-474a7d0cde11",
    "webBuild": "4.70.2",
    "xsecappid": "xhs-pc-web",
    "loadts": "1751515453570",
    "a1": "197ce74d882pw1pejajgbfhh80qpt45f91fpqufu550000259663",
    "webId": "301d36f1aac7907bd7772df81385bf87",
    "acw_tc": "0a0bb0d117515154557554706e5e922de167e476724c005aafc32fad4444a0",
    "websectiga": "8886be45f388a1ee7bf611a69f3e174cae48f1ea02c0f8ec3256031b8be9c7ee",
    "sec_poison_id": "364fa470-19af-4c83-a169-9cb00a1b960c",
    "gid": "yjWSdW4didjYyjWSdW4fYy7iYJUEyUdV0VkDi72ixxY8AU28U942iA888J2jKKq8fWqSJK2i",
    "web_session": "0400698dcff4bb17b14a3f49533a4b725353c3",
    "unread": "{%22ub%22:%22685e17c5000000002201de12%22%2C%22ue%22:%22686201970000000012021caf%22%2C%22uc%22:29}"
}
url = "https://edith.xiaohongshu.com/api/sns/web/v1/homefeed"
data = {
    "cursor_score": "",
    "num": 18,
    "refresh_type": 1,
    "note_index": 39,
    "unread_begin_note_id": "",
    "unread_end_note_id": "",
    "unread_note_count": 0,
    "category": "homefeed_recommend",
    "search_key": "",
    "need_num": 8,
    "image_formats": [
        "jpg",
        "webp",
        "avif"
    ],
    "need_filter_image": False
}
data = json.dumps(data, separators=(',', ':'))
response = requests.post(url, headers=headers, cookies=cookies, data=data)

print(response.text)
print(response)